$(function(){
	var $resMsg=$('#res-msg');
	var $main=$('#main');
	var globalHost=common.globalHost;
	var getHouseVisitList=common.getHouseVisitList;
	var url=globalHost+getHouseVisitList;
	var token=common.getToken();
	var agentInfo=common.getLocalData('H5-agentInfo');
	common.goBackNext();
	var sendData={
		token:token,
		agentId:agentInfo.id,
	}
	var $loadingFail=$('#loadingFail');
	common.requestFormData({
		url:url,
		sendData:sendData,
		resSuccess:function (data) {
			var data=data.res.data.record;
			if(!!data.length){
				$loadingFail.hide();
				var responseDom=buildVisitedHousesList({
                    loadingSelector:$resMsg,
                    imgBasePath:common.imageHost,
                    pageTargetType:"_self",
                    dataList:data
                });
				$main.html(responseDom);
			}else{
				$loadingFail.show();
			}
			
        },
        resFailed:function (data) {

        }
	});
	var $maskControl=$('#mask');
	var $alertSure=$('#alert-sure');
	function _alertNoPassCause(msg){
		$alertSure.children('.alert-content').html(msg).end().removeClass('mask-hide').addClass("mask-show");
		$maskControl.removeClass('mask-hide').addClass("mask-show");
		//只有确定按钮的不进行操作
		$alertSure.children('.alert-sure').off('tap').on('tap',function(e){
		    $maskControl.removeClass('mask-show').addClass("mask-hide");
		    $alertSure.removeClass('mask-show').addClass("mask-hide");
		    e.preventDefault();
		    return false;
		});
	}
	$main.off('tap','.fail-noPassCause').on('tap','.fail-noPassCause',function(e){
		var $this=$(this);
		_alertNoPassCause($this.attr('data-content'))
		e.preventDefault();
		return false;
	})
	function buildVisitedHousesList(options){
		var dataList=options.dataList||[];
        var imgBasePath=options.imgBasePath||"./";
        var $loading=$(options.loadingSelector);
        var arrTemp=[];
        var dataCount=0;
        $.each(dataList,function (idx, obj) {
        	var arrLiList=[];
            dataCount++;
            // console.log(obj.data)
            $.each(obj['data'],function(i,ele){
            	// console.log(ele)
        		var houseAddress=!!ele['houseAddress']?ele['houseAddress']:'';
        		var verifyStatus=!!ele['verifyStatus']?ele['verifyStatus']:'';
        		var point=!!ele['point']?ele['point']:'';
        		var noPassCause=!!ele['noPassCause']?ele['noPassCause']:'';
				var oDiv='';
				if(verifyStatus==2){/*未通过*/
					oDiv='<div><a class="fail-noPassCause" data-content='+noPassCause+' href="javascript:;"><span>未通过，</span>查看原因</a></div>';		
				}else if(verifyStatus==0){/*审核中*/
					oDiv='<div class="auth">审核中</div>';
					
				}else if(verifyStatus==1){/*审核通过*/
					oDiv='<div>+'+point+'积分</div>';	
				}
				var listDom='<li>'+
								'<div>'+houseAddress+'</div>'+oDiv+
				 			'</li>';
				arrLiList.push(listDom);					
			});
			var date=!!obj['date']?obj['date']:'';
            var tempDom='<section>'+
            				'<div>'+date+'</div>'+
            				'<ul>'+
								arrLiList.join("")
            				+'</ul>'+
            			'</section>'
	            arrTemp.push(tempDom) ;
	    });
        $loading.length>0?(dataList.length && dataList.length<10 || dataCount<10 ? $loading.text("已经没有更多信息了").show():$loading.text("").hide()):"无点击加载选择器";
        return arrTemp.join("");
	};
})	